package com.juc.semaphore.semaphore7;

import java.util.concurrent.Semaphore;

public class MyService {
    /***
     * availablePermits 返回此 Semaphore 对象当前可用的许可数
     * 次方法通常用于调试 因为许可的数量可能经常的变动 不是固定的数
     */
    private Semaphore semaphore = new Semaphore(10);
    public void testMethod() {
        try {
            semaphore.acquire();
            System.out.println(semaphore.availablePermits());
            System.out.println(semaphore.availablePermits());
            System.out.println(semaphore.availablePermits());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }finally {
            semaphore.release();
            System.out.println(semaphore.availablePermits());
        }

    }
}
